/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/

#include <qvalidator.h>
#include <qcanvas.h>
#include <qinputdialog.h>
#include "mainwindow.h"

void formConfigDevice::init()
{
    
    //    QRegExp regExpIPAddress("^(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\.(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\.(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\.(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$");
    
    //  QRegExp regExpNetMask("^255\\.255\\.255\\.(?:255|254|252|248|240|224|192|128|0)$|^255\\.255\\.(?:254|252|248|240|224|192|128|0)\\.0$|^255\\.(?:254|252|248|240|224|192|128|0)\\.0\\.0$|^(?:254|252|248|240|224|192|128|0)\\.0\\.0\\.0$");  
    
    //    lineDevIP->setValidator(new QRegExpValidator(regExpIPAddress, this));
    
    //     QDialog::exec();
    
    
    //     item->canvas()->update();
    
    
}

void formConfigDevice::enableOkButton()
{
    btOk->setEnabled(true);
    
}

void formConfigDevice::accept()
{
    done(true);
}



void formConfigDevice::selectElement()
{
 
    if ( listBoxAddrs->currentItem()   == -1 ) {
	 btRemoveAddr->setEnabled(false);
	 btPrefAddr->setEnabled(false);
    }else{
	 btRemoveAddr->setEnabled(true);
	 btPrefAddr->setEnabled(true);
    }
    
}


void formConfigDevice::insert_listBoxAddrs()
{

        bool ok;
        
        QString newText = QInputDialog::getText(
                tr("Address"), tr("Enter new host address:"),
                QLineEdit::Normal, "", &ok, this);
        
        if (ok) 
	        listBoxAddrs->insertItem(newText);
        
      selectElement();
}


void formConfigDevice::remove_listBoxAddr()
{
  if ( listBoxAddrs->currentItem()   != -1 ) {
       listBoxAddrs->removeItem(   listBoxAddrs->currentItem()  );
       selectElement();
  }
}


void formConfigDevice::reinit_listBoxAddr()
{
    
     if ( listBoxAddrs->currentItem()   != -1 ) {
    bool ok;
        
        QString newText = QInputDialog::getText(
                tr("Address"), tr("Enter new host address:"),
                QLineEdit::Normal,  listBoxAddrs->text( listBoxAddrs->currentItem() ), &ok, this);
        
        if (ok) 
	        listBoxAddrs->changeItem(newText,  listBoxAddrs->currentItem()  );
    }       
}
